package f;

import f.f0.f.g;
import f.f0.g.h;
import f.f0.j.f;
import g.c;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.ArrayList;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;

/* compiled from: RealCall */
public final class x implements d {
    public final v a;
    public final h b;
    public final c c;
    @Nullable
    public m d;
    public final y e;
    public final boolean f;
    public boolean g;

    /* compiled from: RealCall */
    public final class b extends f.f0.b {
        static {
            Class cls = x.class;
        }

        public void a() {
            throw null;
        }
    }

    /* compiled from: RealCall */
    public class a extends c {
        public void m() {
            x.this.a();
        }
    }

    public x(v vVar, y yVar, boolean z) {
        this.a = vVar;
        this.e = yVar;
        this.f = z;
        this.b = new h(vVar, z);
        a aVar = new a();
        this.c = aVar;
        aVar.g((long) vVar.w, TimeUnit.MILLISECONDS);
    }

    public void a() {
        h hVar = this.b;
        hVar.d = true;
        g gVar = hVar.b;
        if (gVar != null) {
            f.f0.g.c cVar;
            f.f0.f.c cVar2;
            synchronized (gVar.d) {
                gVar.m = true;
                cVar = gVar.n;
                cVar2 = gVar.j;
            }
            if (cVar != null) {
                cVar.cancel();
            } else if (cVar2 != null) {
                f.f0.c.g(cVar2.d);
            }
        }
    }

    public a0 b() throws IOException {
        synchronized (this) {
            if (this.g) {
                throw new IllegalStateException("Already Executed");
            }
            this.g = true;
        }
        this.b.c = f.a.j("response.body().close()");
        this.c.i();
        Objects.requireNonNull(this.d);
        k kVar;
        try {
            k kVar2 = this.a.a;
            synchronized (kVar2) {
                kVar2.d.add(this);
            }
            a0 c = c();
            kVar = this.a.a;
            kVar.a(kVar.d, this);
            return c;
        } catch (IOException iOException) {
            try {
                IOException iOException2 = d(iOException2);
                Objects.requireNonNull(this.d);
                throw iOException2;
            } catch (Throwable th) {
                kVar = this.a.a;
                kVar.a(kVar.d, this);
            }
        }
    }

    public a0 c() throws IOException {
        ArrayList arrayList = new ArrayList();
        arrayList.addAll(this.a.e);
        arrayList.add(this.b);
        arrayList.add(new f.f0.g.a(this.a.i));
        arrayList.add(new f.f0.e.b(this.a.j));
        arrayList.add(new f.f0.f.a(this.a));
        if (!this.f) {
            arrayList.addAll(this.a.f);
        }
        arrayList.add(new f.f0.g.b(this.f));
        y yVar = this.e;
        m mVar = this.d;
        v vVar = this.a;
        return new f.f0.g.f(arrayList, null, null, null, 0, yVar, this, mVar, vVar.x, vVar.y, vVar.z).a(yVar);
    }

    public Object clone() throws CloneNotSupportedException {
        v vVar = this.a;
        x xVar = new x(vVar, this.e, this.f);
        xVar.d = ((n) vVar.g).a;
        return xVar;
    }

    @Nullable
    public IOException d(@Nullable IOException iOException) {
        if (!this.c.k()) {
            return iOException;
        }
        InterruptedIOException interruptedIOException = new InterruptedIOException("timeout");
        if (iOException != null) {
            interruptedIOException.initCause(iOException);
        }
        return interruptedIOException;
    }
}
